import React from "react";
import { connect } from 'react-redux';
import {fromJS} from 'immutable';
import { actionCreators } from '../store';
import Mysearch from '../../../common/search';
import HistoryDom from '../components/history';
import SearchList from '../components/creatList';
import SearchListItem from '../components/searchListItem';
import { ScollListRowul } from '../style';
import { Toast } from 'antd-mobile';
class SearchBarExample extends React.Component {
    render() {
        let { myColletList, serchKeyArr, getSearchList, serchKey  ,del} = this.props;
        return (<div>
            <Mysearch {...this.props}  />
            <div className="content pfooter">
                {
                    serchKey === "" ? <HistoryDom getSearchList={getSearchList} list={serchKeyArr} del={del} /> : <ScollListRowul>
                        <SearchList data={myColletList} CreatItem={SearchListItem} />
                    </ScollListRowul>
                }
            </div>
        </div>);
    }
}
const mapStateToProps = (state, ownProps) => {
    state= fromJS(state);
    return {
        myColletList: state.getIn(["novel", "myColletList"]).toJS(),
        serchKeyArr: state.getIn(["novel", "serchKeyArr"]).toJS(),
        serchKey: state.getIn(["novel", "serchKey"]),
    };
};
const mapDispatchToProps = (dispatch, ownProps) => {
    return {
        getSearchList(val) {
            if (val === "") {
                Toast.info('请输入选择内容', 2);
                return
            }
            dispatch(actionCreators._getSearchList(val))
        },
        del(){
            dispatch(actionCreators.delHistory())
        }
    };
};
export default connect(mapStateToProps, mapDispatchToProps)(SearchBarExample);
